package net.ikenna.yadet.core.data;

import net.ikenna.yadet.core.cellprocessor.*;

import java.util.*;

public class MapRow implements Row {
    private Map<Object, Object> map;

    public MapRow(Map map) {
        this.map = map;
    }

    public MapRow() {
        map = new HashMap<Object, Object>();
    }

    public Object getColumnValue(String columnName) {
        return map.get(columnName);
    }

    public Row processWith(CellProcessor cellProcssor) {
        for (Object key : map.keySet()) {
            Cell cell = new MapCell(key, map.get(key), this);
            cellProcssor.process(cell);
        }
        return this;
    }

    public int getNumberOfCells() {
        return map.size();
    }

    public Cell getCellFor(String columnName) {
         return new MapCell(columnName, map.get(columnName), this);
    }

    public void put(Object key, Object value) {
        map.put(key, value);
    }

    public Set getColumns() {
        return map.keySet();
    }
}
